{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑商品</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">商品名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="goods_name" lay-verify="required" value="{$goods.goods_name}" class="layui-input" placeholder="商品名称" maxlength="20">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">缩略图：</label>
                            <input type="hidden" name="img1" id="lay-img1" lay-verify="image" value="{$goods.goods_thumb}">
                            <div class="layui-input-block">
                                <div id="lay-upload1">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list1">
                                        <img class="layui-append-img" src="{$goods.goods_thumb}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">一级分类：</label>
                            <div class="layui-input-block">
                                <select name="goods_f_id"  xm-select-search="" xm-select-radio="" xm-select-search-type="dl" lay-search="" id="goods_f_id"  lay-filter="goods_f_id">
                                    <option value="" >---- 一级分类 ----</option>
                                    {foreach name="f_cate" item="v1"}
                                    <option value="{$v1.cate_id}" {$goods.goods_f_id==$v1.cate_id?'selected':''}>{$v1.cate_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">二级分类：</label>
                            <div class="layui-input-block">
                                <select name="goods_s_id"  xm-select-search="" xm-select-radio="" xm-select-search-type="dl" lay-search=""  id="goods_s_id"  lay-filter="goods_s_id">
                                    <option value="" >---- 二级分类 ----</option>
                                    {foreach name="s_cate" item="v2"}
                                    <option value="{$v2.cate_id}" {$goods.goods_s_id==$v2.cate_id?'selected':''}>{$v2.cate_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">是否热门：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="goods_is_hot" value="1" title="热门" {$goods.goods_is_hot==1?'checked':''}>
                                <input type="radio" name="goods_is_hot" value="2" title="非热门" {$goods.goods_is_hot==2?'checked':''}>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">运费模版：</label>
                            <div class="layui-input-block">
                                <select name="goods_freight"  xm-select="select1" xm-select-search="" xm-select-radio="" xm-select-search-type="dl" lay-verify="required">
                                    <option value="" >请选择</option>
                                    {foreach name="fre" item="v1"}
                                    <option value="{$v1.fre_id}" {$v1.fre_id==$goods.goods_freight?'selected':''}>{$v1.fre_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">库存：</label>
                            <div class="layui-input-block">
                                <input type="text" name="goods_stock" lay-verify="required" placeholder="库存" class="layui-input" oninput="value=value.replace(/[^\d]/g,'')" value="{$goods.goods_stock}">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">价格：</label>
                            <div class="layui-input-block">
                                <input type="text" name="goods_price" lay-verify="required" placeholder="价格" class="layui-input" oninput="value=value.replace(/[^\d.]/g,'')"  value="{$goods.goods_price}">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">货号：</label>
                            <div class="layui-input-block">
                                <input type="text" name="goods_code" lay-verify="required" placeholder="货号" class="layui-input" value="{$goods.goods_code}">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">主图</br>（比例1:1）</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="del" id="del2" value="">
                                <input type="hidden" id="hid2" value="{$goods.goods_images}">
                                <input type="hidden" name="photo" id="photo2" value="{$goods.goods_images}">
                                <div id="uploader2" class="container-s">
                                    <div class="queueList">
                                        <div class="placeholder">
                                            <div id="filePicker2"></div>
                                            <p>或将照片拖到这里</p>
                                        </div>
                                    </div>
                                    <div class="statusBar" style="display:none;">
                                        <div class="layui-progress layui-progress-big active-s" lay-showpercent="true">
                                            <div class="layui-progress-bar layui-bg-blue" lay-percent="0%">
                                            </div>
                                            <span></span>
                                        </div>
                                        <div class="info"></div>
                                        <div class="btns">
                                            <div id="goPicker2" class="filePicker2"></div>
                                            <div class="uploadBtn">开始上传</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">服务信息：</label>
                            <div class="layui-input-block">
                                <textarea name="goods_serve" lay-verify="required" class="layui-input " style="height:80px">{$goods.goods_serve}</textarea>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">介绍：</label>
                            <div class="layui-input-block" id="LAY_editor" lay-verify="editor">
                                <p>{$goods.goods_intro}</p>
                            </div>
                        </div>

                        <input type="hidden" value="{$goods_id}" name="goods_id">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    var editor = wk.wang({elem:'#LAY_editor'});
    // 多图
    var n2 = wk.uploads({num:3,type:'png,jpg,jpeg',attr:2,status:'update',url:"{:url('admin/upload/upload')}"});
    function imgDel2(e,obj,hid,del){
        wk.update_del(e,obj,hid,del,n2);
    }
    // 单图
    wk.uploadImg1({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});

    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.verify({
            editor:function(value,item){
                if(editor.txt.html() == '<p><br></p>'){
                    return '请填写介绍内容';
                }
            }
        });
        form.on('submit(component-form-element)', function (data) {
            data.field.goods_intro = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('goodsEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('Goods/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
    });
</script>

</body>
</html>
